home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / coreaids.arc / COPY.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  3KB  |  104 lines

  1. ;    DESC:    Copies existing file to new or existing file         V1.00
  2. ;        using complete path names
  3. ;    IN:    *{OUT_SEG_VAL} segment and
  4. ;        *{OUT_OFFSET} offset of new filename
  5. ;        *{IN_SEG_VAL} segment and
  6. ;        *{IN_OFFSET} offset of old filename
  7. ;    SAMPLE:    Callm    COPY,<OUT_SEG_VAL,OUT_OFFSET,IN_SEG_VAL,IN_OFFSET>,
  8. ;    ###################################################################
  9.  
  10. COPYD Segment Para Public 'DATA'
  11. INHNDL        DW    0            ;input file handle.
  12. OUTHNDL        DW    0            ;output file handle.
  13. BUFFER        DB    4096 DUP(0)        ;data buffer for transfer.
  14. SEGIN        DW    0            ;old filename location.
  15. OFFIN        DW    0
  16. SEGIN2        DW    0            ;new filename location.
  17. OFFIN2        DW    0
  18. STRNG1        DB    'Copying '        ;data strings.
  19. STRNG2        DB    ' to '
  20. COPYD    Ends
  21.  
  22.     Extrn    PUSHALL:Near            ;handle registers.
  23.     Extrn    POPALL:Near
  24.     Extrn    TEXT_WRT:Near            ;display messages.
  25.     Extrn    SCAN_BYT:Near            ;search for strings.
  26.     Extrn    ERRORMSG:Near            ;display errors.
  27.     Extrn    DELETE:Near            ;delete files.
  28.     Extrn    OPEN:Near            ;open files.
  29.     Extrn    READ:Near            ;read from data file.
  30.     Extrn    WRITE:Near            ;write to file.
  31.     Extrn    CREATE:Near            ;create file.
  32.     Extrn    CLOSE:Near            ;close file.
  33.  
  34. COPYC    Segment
  35.     Assume    CS:COPYC,DS:COPYD
  36.     Public    COPY
  37.  
  38.     Include    CALLM.MAC            ;calling macro.
  39.                         ;notice.
  40.     DB    'COPY     - V1.00, Copyright 1987, CoreTechs   ',0DH,0AH
  41.  
  42. COPY    Proc    Near
  43.     Call    PUSHALL
  44.  
  45.     Mov    AX,COPYD            ;set up workarea.
  46.     Mov    DS,AX
  47.  
  48.     Pop    OFFIN                ;old filename specs.
  49.     Pop    SEGIN
  50.     Pop    OFFIN2                ;new filename specs.
  51.     Pop    SEGIN2
  52.  
  53.     Mov    AX,OFFSET STRNG1        ;display 'copying' message.
  54.     Add    AX,8
  55.     Callm    TEXT_WRT,<0,1800H,DS,<OFFSET STRNG1>,AX>,
  56.  
  57.                         ;find end of filename.
  58.     Callm    SCAN_BYT,<SEGIN,OFFIN,0,1>,<DX,DX>
  59.  
  60.                         ;display old filename.
  61.     Callm    TEXT_WRT,<0,1809H,SEGIN,OFFIN,DX>,
  62.  
  63.     Mov    AX,OFFSET STRNG2        ;display 'to' message.
  64.     Add    AX,4
  65.     Callm    TEXT_WRT,<0,1820H,DS,<OFFSET STRNG2>,AX>,
  66.  
  67.                         ;find end of filename.
  68.     Callm    SCAN_BYT,<SEGIN2,OFFIN2,0,1>,<DX,DX>
  69.  
  70.                         ;display new filename.
  71.     Callm    TEXT_WRT,<0,1824H,SEGIN2,OFFIN2,DX>
  72.  
  73.     Callm    OPEN,<SEGIN,OFFIN,0>,<INHNDL>    ;open the old file.
  74.  
  75.                         ;create output file.
  76.     Callm    CREATE,<SEGIN2,OFFIN2,0>,<OUTHNDL>
  77.  
  78.                         ;read a block from input file.
  79. TOP:    Callm    READ,<INHNDL,4096,DS,<OFFSET BUFFER>>,<CX>
  80.  
  81.     JCXZ    DONE                ;if nothing read, eof.
  82.  
  83.                         ;write to the output file.
  84.     Callm    WRITE,<OUTHNDL,CX,DS,<OFFSET BUFFER>>,<AX>
  85.  
  86.     Cmp    AX,CX                ;number of chars. written.
  87.     Je    TOP                ;must equal num of chars read.
  88.  
  89.     Callm    CLOSE,<OUTHNDL>,        ;close output file.
  90.  
  91.     Callm    DELETE,<SEGIN2,OFFIN2>,        ;delete incomplete file.
  92.  
  93.     Callm    ERRORMSG,<19>,            ;load error status.
  94.  
  95. DONE:    Callm    CLOSE,<INHNDL>,            ;close input file.
  96.  
  97.     Callm    CLOSE,<OUTHNDL>,        ;close output file.
  98.  
  99.     Call    POPALL
  100.     Ret
  101. COPY    Endp
  102. COPYC    Ends
  103.     End
  104.